﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SpotsHub.RouteService.Data
{
    [Table("Route_Driver")]
    public class Driver : UserBase
    {
        public virtual ICollection<Package> Packages { get; set; }

        public Driver()
        {
            PreferredLocalities = new List<Locality>();
        }

        public virtual ICollection<Locality> PreferredLocalities { get; set; }
        //public virtual ICollection<LocationType> AssignedLocations { get; set; }

        public virtual ICollection<RoutePlan> RoutePlans { get; set; }

        public bool IsPreferredLocality(int localityId)
        {
            if (PreferredLocalities == null)
            {
                return false;
            }
            // TODO: Must use linq?
            //return PreferredLocalites.Contains(localityId);
            var pls = from l in PreferredLocalities
                      where localityId == l.Id
                      select l.Id;
            return pls.Count() > 0;
        }

        [NotMapped]
        public string PreferredLocalitiesString
        {
            get
            {
                if (PreferredLocalities.Count == 0)
                {
                    return String.Empty;
                }
                return String.Join(",", PreferredLocalities);
            }
        }

    }
}
